//
//  YMTestReportMarkerView.m
//  YMMedical
//
//  Created by y s on 2023/7/22.
//

#import "YMTestReportMarkerView.h"

@interface YMTestReportMarkerView ()

@property (nonatomic, strong) UILabel *lblTime;
@property (nonatomic, strong) UIView *vMark1;
@property (nonatomic, strong) UILabel *lblMark1;
@property (nonatomic, strong) UILabel *lblValue1;

@property (nonatomic, strong) UIView *vMark2;
@property (nonatomic, strong) UILabel *lblMark2;
@property (nonatomic, strong) UILabel *lblValue2;

@end

@implementation YMTestReportMarkerView


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self setUI];
    }
    return self;
}

#pragma mark -- UI
- (void)setUI{
    
    [self addSubview:self.lblTime];
    [self addSubview:self.vMark1];
    [self addSubview:self.lblMark1];
    [self addSubview:self.lblValue1];

    [self addSubview:self.vMark2];
    [self addSubview:self.lblMark2];
    [self addSubview:self.lblValue2];
    
    self.lblTime.frame = CGRectMake([SFitUtil fit:6], [SFitUtil fit:1], self.width-[SFitUtil fit:12], [SFitUtil fit:24]);
    self.vMark1.frame = CGRectMake(self.lblTime.x, [SFitUtil fit:32], [SFitUtil fit:10], [SFitUtil fit:10]);
    self.lblMark1.frame = CGRectMake([SFitUtil fit:19], [SFitUtil fit:25], [SFitUtil fit:40], [SFitUtil fit:24]);
    self.lblValue1.frame = CGRectMake([SFitUtil fit:62], self.lblMark1.y, self.width-[SFitUtil fit:6+62], self.lblMark1.height);
    
    self.vMark2.x = self.lblTime.x;
    self.vMark2.size = self.vMark1.size;
    self.vMark2.y = [SFitUtil fit:56];
    
    self.lblMark2.x = self.lblMark1.x;
    self.lblMark2.size = self.lblMark1.size;
    self.lblMark2.y = [SFitUtil fit:49];
    
    self.lblValue2.x = self.lblValue1.x;
    self.lblValue2.size = self.lblValue1.size;
    self.lblValue2.y = self.lblMark2.y;
}

- (void)setDict:(NSDictionary *)dict{
    _dict = dict;
    self.lblTime.text = [SDataUtil stringOf:dict[@"collectDate"] valid:@""];
    
    self.lblMark1.text = [SDataUtil stringOf:dict[@"minorTermEnglishName"] valid:@""];
    self.lblValue1.text = [SDataUtil stringOf:dict[@"adjustedResDisplay"] valid:@""];
    
    NSString *minorTermName = [SDataUtil stringOf:dict[@"minorTermName"]];
    NSString *sampleType = [SDataUtil stringOf:dict[@"sampleType"] valid:@""];
    if (([sampleType isEqualToString:KLanguage(@"niao_24")] && [minorTermName isEqualToString:KLanguage(@"urinary_microalbumin_txt")])||
        [minorTermName isEqualToString:KLanguage(@"whole_process_c_reactive_protein_txt")]){
        self.lblMark2.text = [SDataUtil stringOf:dict[@"minorTermEnglishName"] valid:@""];
        self.lblValue2.text = [SDataUtil stringOf:dict[@"primaryResDisplay"] valid:@""];
        self.vMark2.hidden = NO;
        
        self.vMark1.frame = CGRectMake(self.lblTime.x, [SFitUtil fit:32], [SFitUtil fit:10], [SFitUtil fit:10]);
        self.lblMark1.frame = CGRectMake([SFitUtil fit:19], [SFitUtil fit:25], [SFitUtil fit:40], [SFitUtil fit:24]);
        self.lblValue1.frame = CGRectMake([SFitUtil fit:62], self.lblMark1.y, self.width-[SFitUtil fit:6+62], self.lblMark1.height);
        
    }else{
        self.vMark2.hidden = YES;
        self.lblMark2.text = @" ";
        self.lblValue2.text = @" ";
        self.vMark1.frame = CGRectMake(self.lblTime.x, [SFitUtil fit:42], [SFitUtil fit:10], [SFitUtil fit:10]);
        self.lblMark1.frame = CGRectMake([SFitUtil fit:19], [SFitUtil fit:35], [SFitUtil fit:40], [SFitUtil fit:24]);
        self.lblValue1.frame = CGRectMake([SFitUtil fit:62], self.lblMark1.y, self.width-[SFitUtil fit:6+62], self.lblMark1.height);
        
    }
}

#pragma mark -- setter and getter
- (UILabel *)lblTime{
    if (_lblTime == nil){
        _lblTime = [SThemeUtil label:@"" color:STheme.H_D1 fontSize:12];
        _lblTime.adjustsFontSizeToFitWidth = YES;
        _lblTime.minimumScaleFactor = 0.6;
    }
    return _lblTime;
}
- (UIView *)vMark1{
    if (_vMark1 == nil){
        _vMark1 = [[UIView alloc] init];
        _vMark1.clipsToBounds = YES;
        _vMark1.layer.cornerRadius = [SFitUtil fit:5];
        _vMark1.backgroundColor = STheme.D12;
    }
    return _vMark1;
}
- (UILabel *)lblValue1{
    if (_lblValue1 == nil){
        _lblValue1 = [SThemeUtil boldLabel:@"" color:STheme.H_D12 fontSize:12];
        _lblValue1.adjustsFontSizeToFitWidth = YES;
        _lblValue1.minimumScaleFactor = 0.6;
        _lblValue1.textAlignment = NSTextAlignmentRight;
    }
    return _lblValue1;
}
- (UILabel *)lblMark1{
    if (_lblMark1 == nil){
        _lblMark1 = [SThemeUtil label:@"" color:STheme.H_D1 fontSize:12];
        _lblMark1.adjustsFontSizeToFitWidth = YES;
        _lblMark1.minimumScaleFactor = 0.6;
    }
    return _lblMark1;
}
- (UIView *)vMark2{
    if (_vMark2 == nil){
        _vMark2 = [[UIView alloc] init];
        _vMark2.clipsToBounds = YES;
        _vMark2.layer.cornerRadius = [SFitUtil fit:5];
        _vMark2.backgroundColor = [SUIUtil colorOf:0x0045D3];
    }
    return _vMark2;
}
- (UILabel *)lblValue2{
    if (_lblValue2 == nil){
        _lblValue2 = [SThemeUtil boldLabel:@"" color:0x0045D3 fontSize:12];
        _lblValue2.adjustsFontSizeToFitWidth = YES;
        _lblValue2.minimumScaleFactor = 0.6;
        _lblValue2.textAlignment = NSTextAlignmentRight;
    }
    return _lblValue2;
}
- (UILabel *)lblMark2{
    if (_lblMark2 == nil){
        _lblMark2 = [SThemeUtil label:@"" color:STheme.H_D1 fontSize:12];
        _lblMark2.adjustsFontSizeToFitWidth = YES;
        _lblMark2.minimumScaleFactor = 0.6;
    }
    return _lblMark2;
}

@end
